﻿using Microsoft.Extensions.Logging;

namespace orleans_demo.Filter
{

    public class LoggingCallFilter : IIncomingGrainCallFilter
    {
        private readonly ILogger<LoggingCallFilter> _logger;

        public LoggingCallFilter(ILogger<LoggingCallFilter> loggerFactory)
        {
            _logger = loggerFactory;
        }

        public async Task Invoke(IIncomingGrainCallContext context)
        {
            _logger.LogInformation(
              $"调用开始: {context.Grain.GetType().Name}.{context.MethodName}");

            try
            {
                await context.Invoke(); // 继续执行实际调用
                _logger.LogInformation("调用成功");
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "调用失败");
                throw;
            }
        }
    }
}
